package com.agg.core.base.dao;

import com.agg.core.base.dto.ExtDTO;
import com.agg.core.base.po.BasePO;
import com.agg.persist.provider.DeleteTemplateProvider;
import com.agg.persist.provider.InsertTemplateProvider;
import com.agg.persist.provider.SelectTemplateProvider;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.*;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

public abstract interface IBaseMapper<T extends BasePO>
        extends BaseMapper<T>{
    Page<T>  getByPage(Page<T> page , @Param("cm") T t, @Param("ex") ExtDTO ex);

   /* @SelectProvider(type = SelectTemplateProvider.class, method = "getByPageTemplate")
    Page<T> getProductPage(Page<T> page, @Param("cm") T t, @Param("ex") ExtDTO ex,String entityMapperId);*/

    @SelectProvider(type = SelectTemplateProvider.class, method = "getByPageTemplate")
    Page<T> getPage(Page<T> page, @Param("cm") T entity, @Param("ex") ExtDTO ex,String entityMapperId);

    @SelectProvider(type = SelectTemplateProvider.class, method = "getListByTemplate")
    List<T> getList(@Param("cm") Object entity, @Param("ex") ExtDTO ex, String entityMapperId);

    @SelectProvider(type = SelectTemplateProvider.class, method = "getByIdTemplate")
    T getById(Serializable id,String entityMapperId);

    @InsertProvider(type = InsertTemplateProvider.class, method = "insertTemplate")
    @Options(useGeneratedKeys=true, keyProperty="list.id", keyColumn="id")
    int insertBatch(@Param("table") String table,
                  List<String> columns,
                  List<String>  propertys,
                  @Param("list") List list);

    @DeleteProvider(type= DeleteTemplateProvider.class,method = "deleteTemplate")
    int deleteBatch(@Param("table") String table,String column,@Param("val") Object val);

    @UpdateProvider(type= DeleteTemplateProvider.class,method = "deleteLogicTemplate")
    int deleteLogicBatch(@Param("table") String table,
                         @Param("delVal")Object delVal,
                         @Param("logicDeleteKey")Object logicDeleteKey,
                         String column,
                         @Param("val") Object val);

    @SelectProvider(type = SelectTemplateProvider.class, method = "getMapByPageTemplate")
    Page<Map<String,Object>> getMapPage(Page<Map> page, @Param("cm") Map<String,Object> entity, @Param("ex") ExtDTO ex, String entityMapperId);


    @SelectProvider(type = SelectTemplateProvider.class, method = "getMapBySqlPageTemplate")
    Page<Map<String,Object>> getMapBySqlPage(Page<Map> page, @Param("cm") Map<String,Object> entity, @Param("ex") ExtDTO ex, String sqlTemplate);


}
